package com.xbts.screen.monitor.domain.token;

import com.xbts.screen.monitor.domain.schedule.UpdateTokenSchedule;

import java.util.Map;

/**
 * 用户密码模式配置信息
 */
public class OauthConfigUserPwdInfo extends OauthConfigBaseInfo{
    /** 密码认证用户名 */
    public String username;//登录平台的用户名，
    /** 认证密码 明文 */
    public String password;

    public OauthConfigUserPwdInfo(){}
    /**
     * 使用默认端口、默认协议构造
     * @param host
     * @param clientId
     * @param clientSecret
     */
    public OauthConfigUserPwdInfo(String host, String clientId, String clientSecret, String username, String password){
        super(host,clientId,clientSecret,GrantType.password);
        this.username = username;
        this.password = password;
        //创建用户名密码模式信息时，将客户端信息进行缓存
        cacheClientInfo();
    }

    /**
     * 使用指定端口、指定协议构造
     * @param host
     * @param clientId
     * @param clientSecret
     */
    public OauthConfigUserPwdInfo(String host, String clientId, String clientSecret, String username, String password, boolean isEnableHttpTest, String httpsPort, String httpPort){
        super(host,clientId,clientSecret,GrantType.password,isEnableHttpTest,httpsPort,httpPort);
        this.username = username;
        this.password = password;
        cacheClientInfo();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void cacheClientInfo(){
        Map<String, OauthConfigBaseInfo> clientInfoMap =  UpdateTokenSchedule.httpConfigMap;
        String clientKey = UpdateTokenSchedule.getKey(this);
        //缓存客户端信息
        clientInfoMap.put(clientKey, this);
    }
}
